package com.neuedu;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class CityMapper extends Mapper<LongWritable, Text,Text, NullWritable> {
    private Text outkey =new Text();
    private NullWritable outValue = NullWritable.get();
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String line = value.toString();
        String[] words = line.split(",");
        StringBuilder stringBuilder = new StringBuilder();
        for(String word:words){
            word = word.trim();
            stringBuilder.append(word);
            stringBuilder.append(",");
        }
        String result = stringBuilder.toString();
        result = result.substring(0,result.length()-1);
        outkey.set(result);
        context.write(outkey,outValue);
    }
}
